package com.example.coupon.dao;

import com.example.coupon.entity.ActivityEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface ActivityMapper {

    @Insert("insert into activity (name, status, start_time, end_time) values (#{name}, #{status}, #{startTime}, #{endTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    Integer insertActivity(ActivityEntity activityEntity);

    @Select("select * from activity where status = #{status} and start_time <= NOW() and end_time > NOW()")
    List<Map<String, Object>> queryCanStartActivity(@Param("status") Integer status);

    @Select("select * from activity where status = #{status} and end_time < NOW()")
    List<Map<String, Object>> queryCanEndActivity(@Param("status") Integer status);

    @Update("update activity set status = #{status} where id = #{id}")
    Integer updateStatusById(@Param("status") Integer status, @Param("id") Long id);

    @Select("select * from activity where id = #{id}")
    Map<String, Object> queryActivityById(@Param("id") Long id);

}